using System;
using System.Windows.Forms;
using System.Drawing;

namespace WinformToolkit.Drawing
{
	/// <summary>
	/// Line tool
	/// </summary>
	class ToolLine : WinformToolkit.Drawing.ToolObject
	{
        public ToolLine()
        {
            Cursor = this.LoadCursor("Line.cur");
        }

        public override void OnMouseDown(DrawArea drawArea, MouseEventArgs e)
        {
            PropertiesLine propertiesLine = new PropertiesLine(e.X, e.Y, e.X + 1, e.Y + 1);

            AddNewObject(drawArea, new DrawLine(propertiesLine)
            {
                ID = drawArea.GenerateObjectId(),
                PenWidth = drawArea.PenWidth,
                Color = drawArea.PenColor,
                DrawLength = drawArea.Options.DrawLineLength,
                LengthConverter = drawArea.Options.LengthConverter
            });
        }

        public override void OnMouseMove(DrawArea drawArea, MouseEventArgs e)
        {
            drawArea.Cursor = Cursor;

            if ( e.Button == MouseButtons.Left )
            {
                Point point = new Point(e.X, e.Y);
                drawArea.GraphicsList[0].MoveHandleTo(point, 2);
                drawArea.GraphicsList[0].UpdateOriginal(drawArea.CanvasRectangle, drawArea.Scale);
                drawArea.Invalidate();
            }
        }

        public override void OnMouseUp(DrawArea drawArea, MouseEventArgs e)
        {
            base.OnMouseUp(drawArea, e);
        }
    }
}
